<template>
  <div class="project-file-detail-view">

    <modules-title class="title-position" titleName="文件详情">
      <template slot="btn">

        <el-button plain icon="el-icon-refresh-left" size="mini" @click="goBack">返回</el-button>

      </template>
    </modules-title>

    <div class="pj-content">

      <el-form :inline="true" ref="elForm" :model="datas" size="small" label-width="110px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="关联编号：">
              <a v-if="datas.model_no" @click="noClick" style="color: #286ee6">{{datas.model_no}}</a>
              <div v-else>无</div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属项目">
              <div>{{datas.project_name}}</div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上传人员：">
              <div>{{datas.creator_name}}</div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上传时间：">
              <div>{{datas.created_at ? dateFormat1('yyyy-mm-dd HH:MM:SS',datas.created_at) : ''}}</div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="文件编号：">
              <div>{{datas.file_no}}</div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="版本号：">
              <div>{{datas.file_version}}</div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="文件类型：">
              <div>{{datas.ipd_type_name ? datas.ipd_type_name : datas.source}}</div>
            </el-form-item>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="文件来源：">-->

<!--              {{datas.source}}-->

<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="8">
            <el-form-item label="文件状态：">
              <span v-if="!datas.file_effect">草稿</span>
              <span v-else-if="datas.file_effect == 1">生效</span>
              <span v-else-if="datas.file_effect == 2">作废</span>
            </el-form-item>
          </el-col>

          <template v-if="datas.model_children_type == 'inspection_result' || datas.model_children_type == 'computation_sheet' || datas.model_children_type == 'inspection_map'">

            <el-col :span="8">
              <el-form-item label="检品名称：">
                <span>{{datas.sample_name}}</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="批号：">
                <span>{{datas.batch_no}}</span>
              </el-form-item>
            </el-col>

          </template>

          <template v-if="datas.model_children_type == 'inspection_result'">

            <el-col :span="8">
              <el-form-item label="检验结论：">
                <span v-if="datas.inspection_conclusion == 1">合格</span>
                <span v-else-if="datas.inspection_conclusion == 2">不合格</span>
                <span v-else-if="datas.inspection_conclusion == 3">无结论</span>
              </el-form-item>
            </el-col>

          </template>

          <el-col :span="8" v-if="datas.model_type == 'inspection_task'">
            <el-form-item label="报告来源：">
              <span v-if="!datas.if_wd">检验任务</span>
              <span v-else>稳定性实验</span>

            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="文件：">
              <file-preview :file-list="datas?[datas]:[]" />
            </el-form-item>
          </el-col>

        </el-row>

      </el-form>


      <item-title v-if="historys.length" title="历史记录" />

      <el-table
        v-if="historys.length"
        size="medium"
        :data="historys"
        border
        style="width: 100%">
        <el-table-column
          align="center"
          prop="creator_name"
          label="上传人员">
        </el-table-column>
        <el-table-column
          align="center"
          label="上传时间">
          <template slot-scope="scope">
            <span>{{scope.row.created_at ? dateFormat1('yyyy-mm-dd HH:MM:SS',scope.row.created_at) : ''}}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="file_no"
          label="文件编号">
        </el-table-column>
        <el-table-column
          align="center"
          label="文件版本"
          prop="file_version">
        </el-table-column>
        <el-table-column
          align="center"
          label="文件类型">
          <template slot-scope="scope">
            <span v-if="scope.row.model_children_type == 'project_design_book_tech'">项目技术方案书</span>
            <span v-else-if="scope.row.model_children_type == 'project_design_book_budget'">项目预算方案书</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="文件状态">
          <template slot-scope="scope">
            <span>{{scope.row.file_effect?'生效':'未生效'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作">
          <template slot-scope="scope">
            <el-button size="medium" type="text" @click="onClick(scope.row)">
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>

    </div>

  </div>
</template>

<script>
    export default {
        name: "index",
        data:function () {
            return{
                datas:{},
                historys:[],
                inspections:[],
                childModel:{}
            }
        },
        created(){
            if (this.$store.getters.fileChildModel.length){
                this.childModel = this.$store.getters.fileChildModel
            }else {
                this.$store.dispatch('sys/getFileSource').then(()=>{
                    this.childModel = this.$store.getters.fileChildModel
                })
            }
            if (this.$route.query.id){
                this.getData(this.$route.query.id)
            }

        },
        methods:{
            getSource:function(){

            },
            getData:function (id) {
                this.$api.PROJECT_START_FILE_DETAIL(id).then(res=>{
                    if (res.code == 200){
                        this.datas = res.data

                        if (this.datas.model_children_type){
                            this.datas.source = this.childModel[this.datas.model_children_type]
                        }else {
                            this.datas.source = this.childModel[this.datas.model_type]
                        }
                        this.getInspection();
                        if (this.datas.file_no){
                            this.getHistory()
                        }
                    }else{
                        this.$message.error(res.msg)
                    }
                })
            },
            getInspection:function(){
                this.$api.PROJECT_START_FILE_INSPECTION(this.datas.id).then(res=>{
                    if (res.code == 200){
                        this.inspections = res.data
                    }else {
                        this.$message.error(res.msg)
                    }
                })
            },
            getHistory:function () {
                this.$api.PROJECT_START_FILE_HISTORY(this.datas.file_no,this.datas.id).then(res=>{
                    if (res.code == 200){
                        this.historys = res.data || []
                    }else{
                        this.$message.error(res.msg)
                    }
                })
            },
            noClick:function () {
                if (this.datas.model_type == 'project_task'){
                    this.$router.push({name:'projectManagementTaskDetail',query:{id:this.datas.task_id}})
                } else if (this.datas.model_type == 'project_design_book'){
                    this.$router.push({name:'projectManagementDetails',query:{id:this.datas.project_id}})
                } else if (this.datas.model_type == 'inspection_task') {
                    this.$router.push({
                        path: '/sampleInspection/taskDetails',
                        query: { id: this.datas.model_id }
                    })
                } else if (this.datas.model_type == 'inspection_apply') {
                    this.$router.push({
                        path: '/sampleInspection/details',
                        query: { type: 1, id: this.datas.model_id }
                    })
                }
            },
            onClick:function (row) {
                this.getData(row.id)
            },
            goBack:function () {
                this.$router.back()
            }
        }
    }
</script>

<style lang="scss" scoped>
  @import "../../../../assets/scss/views/projectManagement/file/detail.scss";
</style>
